var express = require('express');
var router = express.Router();
let knex = require('../common/getknex')();
var iconv = require('iconv-lite');
/* GET users listing. */
router.get('/', async (req, res, next) => {
  let info_pri = await knex('data').orderBy('id', 'desc').limit(1);
  info_de = info_pri[0].info;
  let info_de_arr = info_de.split('\n')[0].split(';');
  let info_de_arr1 = info_de_arr.map((val) => {
    if (val !== '') {
      return val.replace(/.*=(.*)/, "$1")
    }
  })
  console.log(info_de_arr1);
  let info = {
    wind_scale: info_de_arr1[0],
    direction: info_de_arr1[1],
    temperature: info_de_arr1[3],
    humidity: info_de_arr1[2]
  }
  res.json(info);
});

module.exports = router;
